<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<%@ page import="com.fengke.csc.config.HostConfig" %>
<%
	HostConfig hostConfig = (HostConfig) request.getSession().getServletContext().getAttribute("hostConfig");
%>
<!DOCTYPE html>
	<!--[if lt IE 7 ]> <html lang="en" class="no-js ie6"> <![endif]-->
	<!--[if IE 7 ]>    <html lang="en" class="no-js ie7"> <![endif]-->
	<!--[if IE 8 ]>    <html lang="en" class="no-js ie8"> <![endif]-->
	<!--[if IE 9 ]>    <html lang="en" class="no-js ie9"> <![endif]-->
	<!--[if (gt IE 9)|!(IE)]><!--> <html lang="en" class="no-js"><!--<![endif]-->
	<head>
		<title><%=hostConfig.getWebSiteName() %></title>
		<meta name="keywords" content="<%=hostConfig.getWebSiteName() %>" />
		<meta name="description" content="<%=hostConfig.getWebSiteName() %>" />
		<jsp:include page="../gadget/include_header.jsp"></jsp:include>
	</head>
	<body>
		<!-- 头信息 Start -->
		<jsp:include page="../gadget/main_header.jsp"></jsp:include>
		<!-- 头信息 End -->
		<jsp:include page="../gadget/main_sidebar.jsp"></jsp:include>
		<div class="main-content">
			<div class="breadcrumbs" id="breadcrumbs">
				<script type="text/javascript">
					try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
				</script>

				<ul class="breadcrumb">
					<li>
						<i class="icon-home home-icon"></i>
						<a href="#">首页</a>
					</li>
					<li class="active"><s:property value="getText('product.type.' + productVO.productModel.productType)" />管理</li>
				</ul><!-- .breadcrumb -->
			</div>
			<div class="page-content">
				<div class="page-header">
					<h1 style="display: inline-block;">
						<s:property value="getText('product.type.' + productVO.productModel.productType)" />列表
						<small>
							<i class="icon-double-angle-right"></i>
							 查看
						</small>
					</h1>
					<div id="nav-search" style="float: right;">
						<form class="form-search" method="post" action="product/showProductList.action" id="csc_product_search_form">
							<input type="hidden" value="1" name="pageBean.currentPage" id="csc_prod_search_currentPage">
							<input type="hidden" name="productVO.productModel.mproductType" value="<s:property value='productVO.productModel.mproductType' />" />
							<label for="csc_prod_search_fullName">主题：</label><input type="text" name="productVO.productModel.fullName" id="csc_prod_search_fullName" value="<s:property value='productVO.productModel.fullName' />">
							<label for="csc_prod_search_isMarketable" style="margin-left: 10px;">是否上架：</label>
							<select id="csc_prod_search_isMarketable" name="productVO.productModel.isMarketable">
								<option value="true" <s:if test="productVO.productModel.isMarketable != null && productVO.productModel.isMarketable">selected="selected"</s:if> >已上架</option>
								<option value="false" <s:if test="productVO.productModel.isMarketable != null && !productVO.productModel.isMarketable">selected="selected"</s:if> >未上架</option>
							</select>
							<s:if test='productVO.productModel.mproductType == 0'>
								<label for="csc_prod_search_isTop" style="margin-left: 10px;">是否置顶：</label>
								<select id="csc_prod_search_isTop" name="productVO.productModel.isTop">
									<option value="true" <s:if test="productVO.productModel.isTop != null && productVO.productModel.isTop">selected="selected"</s:if> >已置顶</option>
									<option value="false" <s:if test="productVO.productModel.isTop != null && !productVO.productModel.isTop">selected="selected"</s:if> >未置顶</option>
								</select>
							</s:if>
							<button class="btn btn-xs btn-primary" onclick="$('#csc_prod_search_currentPage').attr('value', '1');$('#csc_product_search_form').submit();" style="margin-left: 10px;"><i class="icon-search align-top bigger-125"></i>查询</button>
						</form>
					</div><!-- #nav-search -->
				</div><!-- /.page-header -->
				<div class="row">
					<div class="col-xs-12">
						<!-- PAGE CONTENT BEGINS -->

						<div style="margin-bottom: 10px">
							<form id="csc_product_preCreate_form" action="product/preCreateProduct.action" method="post">
								<input type="hidden" name="productVO.productModel.mproductType" value="<s:property value='productVO.productModel.mproductType' />" />
							</form>
							<form id="csc_product_preUpdate_form" action="product/preUpdateProduct.action" method="post">
								<input type="hidden" id="csc_prod_update_productId" name="productVO.productModel.id" />
							</form>
							<form id="csc_product_delete_form" action="product/deleteProduct.action" method="post">
								<input type="hidden" id="csc_prod_deletedProductIds" name="value.deletedProductIds" value="" />
								<input type="hidden" name="productVO.productModel.mproductType" value="<s:property value='productVO.productModel.mproductType' />" />
							</form>
							<form id="csc_product_detail_form" action="product/productDetail.action" method="post">
								<input type="hidden" id="csc_prod_detailProductId" name="productVO.productModel.id" value="" />
								<input type="hidden" name="productVO.productModel.mproductType" value="<s:property value='productVO.productModel.mproductType' />" />
							</form>
							<form id="csc_product_marketable_form" action="product/marketableProduct.action" method="post">
								<input type="hidden" id="csc_prod_marketableProductIds" name="value.marketableProductIds" value="" />
								<input type="hidden" id="csc_prod_isMarketable" name="value.isMarketable" value="" />
								<input type="hidden" name="productVO.productModel.mproductType" value="<s:property value='productVO.productModel.mproductType' />" />
							</form>
							<button onclick="preCreateProduct();" class="btn btn-primary"><i class="icon-beaker align-top bigger-125"></i>新增</button>
							<button onclick="deleteProduct();" class="btn btn-grey"><i class="icon-trash icon-1.5x"></i>删除</button>
							<button onclick="onListing();" class="btn btn-success"><i class="icon-cloud-upload icon-1.5x"></i>上架</button>
							<button onclick="soldOut();" class="btn btn-danger"><i class="icon-cloud-download icon-1.5x"></i>下架</button>
						</div>
						
						<jsp:include page="../gadget/include_pageMessage.jsp"></jsp:include>
						
						<div class="table-responsive dataTables_wrapper">
							<s:if test="0 == productVO.productModel.mproductType">
								<jsp:include page="merchandiseList.jsp"></jsp:include>
							</s:if>
							<s:elseif test="1 == productVO.productModel.mproductType">
								<jsp:include page="activitiesList.jsp"></jsp:include>
							</s:elseif>
							<s:else>
								<div>关键参数为空！productType is null</div>
							</s:else>
							
							<s:if test="productVOList != null && productVOList.size > 0">
								<jsp:include page="../gadget/include_pagination.jsp"></jsp:include>
							</s:if>
						</div>
						
					</div>
				</div>
			</div>
		</div>
			
	<jsp:include page="../gadget/include_script.jsp"></jsp:include>
	<script type="text/javascript">
		var mproductType = '<s:property value="productVO.productModel.mproductType" />';
		$(document).ready(function () {
			$('#sidebar_product').addClass('open');
			$('#sidebar_product').addClass('active');
			if(mproductType == 0) {
				$('#sidebar_product_manager').addClass('active');
			} else if(mproductType == 1) {
				$('#sidebar_activities_manager').addClass('active');
			} else {
				alert('关键参数缺失！productType is null');
			}
		});
		jQuery(function($) {
			
			$('table th input:checkbox').on('click' , function(){
				var that = this;
				$(this).closest('table').find('tr > td:first-child input:checkbox')
				.each(function(){
					this.checked = that.checked;
					$(this).closest('tr').toggleClass('selected');
				});
					
			});
		
		});
		
		function preCreateProduct() {
			$('#csc_product_preCreate_form').submit();
		}
		
		function preupdateproduct(productId) {
			$('#csc_prod_update_productId').attr('value', productId);
			$('#csc_product_preUpdate_form').submit();
		}
		
		function deleteProduct() {
			var selectedIds = '';
			$('#product_list_table').find('tr > td:first-child input:checkbox').each(function(){
				if(this.checked == true || this.checked == 'checked') {
					if(selectedIds != '') {
						selectedIds += ' ';
					}
					selectedIds += $(this).attr('lang');
				}
			});
			if($.trim(selectedIds) == '') {
				alert('请选择待删除的条目！');
				return ;
			}
			$('#csc_prod_deletedProductIds').attr('value', selectedIds);
			$('#csc_product_delete_form').submit();
		}
		// 上架
		function onListing() {
			var selectedIds = '';
			$('#product_list_table').find('tr > td:first-child input:checkbox').each(function(){
				if(this.checked == true || this.checked == 'checked') {
					if(selectedIds != '') {
						selectedIds += ' ';
					}
					selectedIds += $(this).attr('lang');
				}
			});
			if($.trim(selectedIds) == '') {
				alert('请选择待上架的条目！');
				return ;
			}
			$('#csc_prod_marketableProductIds').attr('value', selectedIds);
			$('#csc_prod_isMarketable').attr('value', true);
			$('#csc_product_marketable_form').submit();
		}
		
		function soldOut() {
			var selectedIds = '';
			$('#product_list_table').find('tr > td:first-child input:checkbox').each(function(){
				if(this.checked == true || this.checked == 'checked') {
					if(selectedIds != '') {
						selectedIds += ' ';
					}
					selectedIds += $(this).attr('lang');
				}
			});
			if($.trim(selectedIds) == '') {
				alert('请选择待上架的条目！');
				return ;
			}
			$('#csc_prod_marketableProductIds').attr('value', selectedIds);
			$('#csc_prod_isMarketable').attr('value', false);
			$('#csc_product_marketable_form').submit();
		}
		
		function productDetail(productId) {
			$('#csc_prod_detailProductId').attr('value', productId);
			$('#csc_product_detail_form').submit();
		}
		
		function gotoPage(currentPage) {
			$('#csc_prod_search_currentPage').attr('value', currentPage);
			$('#csc_product_search_form').submit();
		}
	</script>
	</body>
</html>